package com.hwj.exception;


import com.hwj.utils.JsonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(CustomAuthException.class)
    @ResponseBody
    public JsonResponse customer(HttpServletRequest request, CustomAuthException e) {
        return JsonResponse.failResponse(e.getCode(), e.getMsg(),null);
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResponse error(HttpServletRequest request, Exception e) {
        log.error("异常信息：",e);
        return JsonResponse.failResponse(-1, "服务端异常："+e.getMessage(),null);
    }


}
